<?php

namespace App\Repositories;

use App\Models\TestingUserRemark;
use Cache;
class TestingUserRemarkRepository extends Repository
{
    static $tag = 'testing.UserRemark';


    /*
     * 备注信息处理
     */
    public function Remark($data){
       $user = $this->checkRemark($data['rid'],$data['uid'],$data['tid']);
        if($user){
           return $this->updateRemark($data);
        }else{
            return $this->storeRemark($data);
        }
    }

    /**检查备注
     * @param $rid
     * @param $uid
     * @param $tid
     * @return mixed
     */
    public function checkRemark($rid,$uid,$tid){
        return TestingUserRemark::where('rid', $rid)
            ->where('uid',$uid)
            ->where('tid',$tid)
            ->orderBy('id', 'desc')
            ->first();
    }

    /**更新备注
     * @param $data
     * @return mixed
     */
    public function updateRemark($data){
        return TestingUserRemark::where('uid', $data['uid'])
            ->where('rid',$data['rid'])
            ->where('tid',$data['tid'])
            ->update(['remark' => $data['remark']]);
    }


    public function storeRemark($data){
        return  TestingUserRemark::create($data);
    }


    public function cacheTime()
    {
        return config('testing.common_cache_time');
    }


    public function model()
    {
        return app(TestingUserRemark::class);
    }

    public function tag()
    {
        return self::$tag;
    }
}